From 720e5e216f214e1aba81fbf4691190731d85cef9 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Tue, 24 Jun 2008 22:51:19 +0000 Subject: [PATCH] igo8, psp: Use new unicode functions of CET lib. --- igo8.c | 23 ++++++++++++++++++++++- psp.c | 27 +++++++-------------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/igo8.c b/igo8.c index 56ec35158..c016a88dc 100644 --- a/igo8.c +++ b/igo8.c @@ -62,6 +62,8 @@ #include #include #include "defs.h" +#include "cet.h" +#include "cet_util.h" #define TRUE 1 #define FALSE 0 @@ -228,8 +230,26 @@ static void write_igo8_track_point(const waypoint *wpt) // // Please replace this with a much more filled out and correct version if you see // fit. -unsigned int ascii_to_unicode_2(char* dst, unsigned int dst_max_length, char* src) + +/* 2008/06/24, O.K.: Use CET library for ascii-> unicode 2 converter */ + +unsigned int ascii_to_unicode_2(char *dst, const int dst_max_length, const char *src) { +#if 1 + short *unicode; + int len; + + unicode = cet_str_any_to_uni(src, &cet_cs_vec_ansi_x3_4_1968, &len); + + len += 1; /* include terminating null */ + len *= 2; /* real size */ + if (len > dst_max_length) len = dst_max_length; + memcpy(dst, unicode, len); + + xfree(unicode); + + return len; +#else unsigned int current_src_position = 0; unsigned int current_dst_position = 0; unsigned short current_unicode_char; @@ -249,6 +269,7 @@ unsigned int ascii_to_unicode_2(char* dst, unsigned int dst_max_length, char* sr } return current_dst_position; +#endif } void write_header() diff --git a/psp.c b/psp.c index 61d37bbc4..8934b4eb8 100644 --- a/psp.c +++ b/psp.c @@ -44,30 +44,17 @@ static void psp_write_str(const char *str) { if (str && *str) { - const char *cin = str; - gbint16 *tmp, *res; - int len = 0; + short *unicode; + int len; /* convert UTF-8 string into a unicode sequence */ /* not perfect, but enough for us */ + unicode = cet_str_any_to_uni(str, global_opts.charset, &len); + if (len > MAXPSPSTRINGSIZE) len = MAXPSPSTRINGSIZE; + gbfputc((unsigned char)len, psp_file_out); + if (len) gbfwrite(unicode, 2, len, psp_file_out); - res = tmp = xmalloc(strlen(str) << 1); - while (*cin) { - int bytes, value; - - if (cet_utf8_to_ucs4(cin, &bytes, &value) != CET_SUCCESS) - value = CET_NOT_CONVERTABLE_DEFAULT; - *tmp++ = value; - cin += bytes; - len++; - if (len == (MAXPSPSTRINGSIZE >> 1)) break; - } - gbfputc(len, psp_file_out); - tmp = res; - while (len--) - /* ! we need LE values, don't use gbfwrite ! */ - gbfputint16(*tmp++, psp_file_out); - xfree(res); + xfree(unicode); } else gbfputc(0, psp_file_out); -- 2.30.2